<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8" />
    <title>资产入库</title>
    <link rel="stylesheet" type="text/css" href="/static/preview/preview.css?v=2" >
    <link rel="stylesheet" type="text/css" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="/static/basic/plugins/easyui/themes/bootstrap/easyui.css">
	<link rel="stylesheet" type="text/css" href="https://cdn.staticfile.org/font-awesome/5.12.1/css/all.min.css" >
	<link rel="stylesheet" type="text/css" href="/static/m.css?v=6" >
	
</head>
<body>
<div id="window-mmask" class="window-mmask" ><div class="window-mmask-msg" >页面加载中,请稍候...</div></div>
<div class="easyui-layout" data-options="fit:true"  >
	<div data-options="region:'center'" >
		<table id="gridList" ></table>
	</div>
</div>
<div id="searchbar">
<div class="maction">
		<a href="javascript:void(0)" id="addButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-plus mbutton'">新增</a>
		<a href="javascript:void(0)" id="editButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-pencil-alt mbutton'">编辑</a>
		<a href="javascript:void(0)" id="removeButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-trash-alt mbutton color-c5'">删除</a>
		<a href="javascript:void(0)" id="btn1" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-eye mbutton'">预览资产标签</a>
</div>
<form id="searchForm" >
	资产分类<input id="search-asset_class_id" name="class_id"  >
	资产状态<input id="search-status" name="status"  >
	<a id="searchButton" href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-search mbutton'" >查询</a>
</form>
</div>
<div id="viewcodeDlg" class="easyui-dialog" title="资产标签预览" data-options="modal:true,iconCls:'icon-win',closed:true">
		<div id="codeimg"></div>
</div>
<script src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js"></script>
<script src="/static/basic/plugins/qrcodejs/qrcode.min.js"></script>
<script src="/static/basic/plugins/easyui/jquery.easyui.min.js"></script>
<script src="/static/init.js?v=1"></script>
<script src="/static/basic/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>	
<script src="/static/searchEdit.js?v=4"></script>
<!-- <script src="https://cdn.staticfile.org/moment.js/2.24.0/moment.min.js"></script> -->
<script src="/static/basic/plugins/plupload-2.1.9/js/plupload.full.min.js"></script>
<script src="/static/basic/plugins/plupload-2.1.9/js/i18n/zh_CN.js"></script>
<script src="/static/plupload-v0.2.js?v=9"></script>
<script src="/static/basic/plugins/baiduTemplate.js"></script>
<script id="t_2" type="text/html">
<%for(var i=0;i<data.length;i++){%>
<div class="multi-item">
	<img item_id="<%=data[i].id%>" src="<%=data[i].url%>"; style="<%=style%>" class="img-responsive img-thumbnail">
	<em item_id="<%=data[i].id%>" class="close" title="删除这张图片" onclick="<%=delcallback%>(this)">×</em>
</div>
<%}%>
</script>
<script id="t_3" type="text/html">
<div class="preview_show" id="preview_show">
	<div class="preview_show_bg"></div>
	<div class="preview_show_main" id="preview_show_main"
		style="background-size: 100% 64px;">
		<div id="preview_historyback"></div>
		<div class="spinner">
			<div class="dot1"></div>
			<div class="dot2"></div>
		</div>
		<div class="iframe_prev" style="display: none;"></div>
		<iframe class="preview_iframe" id="vcard_iframe" frameborder="0"
			scrolling="yes" src="<%=url%>" style="height: <%=dialogHeight%>px; visibility: visible; width: 375px;"></iframe>
		<div class="scrolling_line" id="preview_scrolling_line"
			style="margin-left: 365px;"></div>
	</div>
	<div class="left_block">
		<div class="left_block_head">
			<p>与实际手机显示效果</p>
			<p>有微小差异，请扫码查看</p>
		</div>
		<div id="qr_preview_img"></div>
		<div class="left_block_end">
			<div class="left_block_url">
				<a href="<%=url%>" class="biz_link" target="_blank">打开新窗口预览</a>
			</div>
		</div>
	</div>
	<!-- <div class="left_footer">
		<div class="left_footer_head">当前预览模拟</div>
		<div class="dropdown cli-dropdown inline">
			<button class="btn white dropdown-toggle" data-toggle="dropdown"
				aria-expanded="false">苹果 7</button>
			<div class="dropdown-menu">
				<a class="dropdown-item" id="huaweiP9">华为 P9</a><a
					class="dropdown-item" id="minote2">小米 Note2</a><a
					class="dropdown-item" id="galaxys6">三星S6</a><a
					class="dropdown-item" id="iPhone7">苹果 7</a><a class="dropdown-item"
					id="iPhone7p">苹果 7 Plus</a>
			</div>
		</div>
	</div> -->
	<div class="preview_show_close"></div>
</div>
</script>
<script>
var template=baidu.template;//模板

var domain="http://zy.lvzhi.com";
//var domain="http://localhost:9093";
function viewcodeButton(){
	var selectRows=grid1.grid.datagrid('getSelections');
	
	if(selectRows.length>0){
		var id=selectRows[0].id;
		var url=domain+"/asset/asset/preview?id="+id;
		var html=template('t_3',{"url":url,"height":dialogHeight});
		$("body").append(html);
		var qrcode = new QRCode($('#qr_preview_img')[0], {width : 250,height : 250});
		qrcode.makeCode(url);
		$(".preview_show_bg,.preview_show_close").click(function(){
			$("#preview_show").remove();
		});
	}else{
		$.messager.alert("提示", "请选择一条数据！");
	}
}
//删除图
function deletePicture(em){
	$("#picture2").html("");
	//$(em).parent().remove();
	$("input[name=picture]").val("");
	$("#picture_url").textbox("clear");
}
var options={
		page_id:207,
		grid_id:"gridList",
		sqlname:"grid_207_asset",
		showCheckbox:false,
		rownumbers:false,
};
var uploader1=null;
var editRow=null;
var dialogInit=false;
	//document ready
	$(function(){
		grid1=new uniontrip.datagrid.searchEdit(options);
		dialogHeight=$(window).height()*0.8;
		$('#searchButton').bind('click',grid1.load);//查询操作绑定事件
		$('#addButton').bind('click', function(){
			editRow=null;
			EditDialog.dialog('setTitle','新增资产').dialog('open');
		});//新增行绑定事件
		$('#editButton').bind('click',function(){
			gridSelectRow(grid1.grid,function(row){
				editRow=row;
				EditDialog.dialog('setTitle','编辑资产').dialog('open');
			});
		});//编辑按钮绑定事件
		$('#removeButton').bind('click',onDelete);//删除行绑定事件
		$('#saveButton').bind('click', grid1.accept);//保存datagrid绑定事件
		$('#cancelEditButton').bind('click',grid1.cancelEditing);//取消行编辑绑定事件
		$('#endEditingButton').bind('click', grid1.endEditing);//结束行编辑绑定事件
		$('#rejectButton').bind('click', grid1.rejectChanges);//撤销编辑绑定事件		
	    $('#showChangesButton').bind('click',grid1.showChanges);//信息变更提示
	    $('#btn1').bind('click', viewcodeButton);
	    //初始化搜索框
	    initsearch();
	    //initsessioninfo();
	    EditDialog=$("<div/>").appendTo("body").dialog({
			title:"新增资产",
			cls:"m-dialog",
			/*width:'100%',
			height:dialogHeight,*/
			href:'/grid/form/insert/view?grid_id=207',
			modal:true,
			closed:true,
			maximized:true,
			onClose:function(){
				console.log('onClose');
				if(uploader1){
					uploader1.destroy();
					uploader1=null;
				}
			},
			onBeforeClose:function(){
				editRow=null;
				$("#form-1").form('clear');
				$("#picture2").html("");
				//return true;
			},
			 buttons: [{
				text:'保存',
				iconCls:'fas fa-save mbutton',
				handler:save
			},{
				text:'取消',
				iconCls:'fas fa-times mbutton',
				handler:function(){
					EditDialog.dialog('close')
				}
			}],
			onOpen:function(){
				console.log('onOpen');
				if(editRow){
					$("#form-1").form('load',editRow);
					var a=new Array();
		  			a.push({id:editRow.picture_id,url:editRow.picture_url});
					var html=template('t_2',{"delcallback":"deletePicture","style":"width:100px;height:100px;","data":a});
					$("#picture2").html(html);
				}else{
					
				}
				if(!uploader1&&dialogInit){
					var pickfiles1=$('#picture_url').next('span').find(".l-btn-text")[0];
					if(pickfiles1){
						initUpload(pickfiles1);
					}
				}
				/* var pickfiles1=$('#picture_url').next('span').find(".l-btn-text")[0];
				if(pickfiles1){
					initUpload(pickfiles1,uploader1);
				} */
			},
			onLoad:function(){
				console.log('onLoad');
				if(!dialogInit){
					if(editRow){
						$("#form-1").form('load',editRow);
						var a=new Array();
			  			a.push({id:editRow.picture_id,url:editRow.picture_url});
						var html=template('t_2',{"delcallback":"deletePicture","style":"width:100px;height:100px;","data":a});
						$("#picture2").html(html);
					}else{
						
					}
				}
				var pickfiles1=$('#picture_url').next('span').find(".l-btn-text")[0];
				if(pickfiles1){
					dialogInit=true;
					initUpload(pickfiles1);
				}else{
					dialogInit=true;
					setTimeout(function(){
						  pickfiles1=$('#picture_url').next('span').find(".l-btn-text")[0];
						  initUpload(pickfiles1);
					  },1000);
				}
				
			}
		});
	    
	    
	    
	  
	});
	function onDelete(){
		gridConfirm(grid1.grid,"是否确认删除",function(selectRow){
			$._post("/authenticated/asset/delete",JSON.stringify({ids:selectRow.id}),function(result){
				if(result.success){
    				grid1.load();
    			}else{
    				$.messager.alert("提示", "删除失败！<br>"+result.message);
    			}
			});
		});
	}
	var pictureArray=new Array();
	function initUpload(button){
		if(uploader1==null){
			console.log('initUpload');
			myOption1={
			  		file_id:1,
			  		browse_button: button,
			  		//uploadfiles:"uploadfiles1",//开始上传按钮id
			  		multi_selection:false,//一次选择多个文件
			  		multiple_queues:true,//多次上传
			  		filters : {
			              mime_types: [
			                  {title : "选择图片(jpg,jpeg,png格式)", extensions : "jpg,jpeg,png"}  
			              ]
			          },
			  		FileUploadedCallBack: function(up, file, data){//单个文件上传后回调
			  			if(file.status==plupload.DONE){
							//$("input[name=logo_image_id]").val(item_id);
							//$("#logo_image").textbox("setValue",data.access_url);
							pictureArray.push({id:data.item_id,url:data.access_url});
							$("#picture_url").textbox("setValue",data.access_url);
						}
			  		},
			  		FilesAddedCallBack:function(up, files){//添加到文件队列后回调
			  			uploader1.start();
			  			/* uploader1.previewImage(files[0], function (imgsrc) {
			  				//$("#picture2").find("img").attr("src",imgsrc);
			  				var array=new Array();
			  				array.push({access_url:imgsrc});
			  				var html=bt('t_2',{"style":"width:100px;height:100px;","data":array});
			  				$("#picture2").html(html);
			              }); */
			  			//var f=files[0];
			  			//$("#certFileName").text(f.name);
			  			//$("#cert").show();
			  			//$.messager.alert("提示", JSON.stringify(files));
			  		},
			  		UploadCompleteCallBack: function(up, files) {//全部上传完成回调
			  			var html=template('t_2',{"delcallback":"deletePicture","style":"width:100px;height:100px;","data":pictureArray});
						$("#picture2").html(html);
						pictureArray.length=0;
			  		}
			  };
		  uploader1=new Uploader(myOption1);
		}
	}
	function save(){
		if($("#form-1").form('enableValidation').form('validate')){
			$._post("/authenticated/asset/save",$("#form-1").serializeObject(),function(result){
				if(result.success){
					info( "保存成功！");
					EditDialog.dialog('close');
					grid1.load();
				}else{
					$.messager.alert("提示", "保存失败！<br>"+result.message);
				}
			});
		}
	}
	
	/**
	 * 新增一行
	 */
	function addRow(){
		var newRowData={id:guid(),creator_id:sessionuser.id,creator_name:sessionuser.nickname,create_time:moment().format('YYYY-MM-DD')};//初始化行数据
		grid1.grid.datagrid('append',newRowData);	
	}

	function onDeleteRow(){
		gridConfirm(grid1.grid,"是否确认删除",deleteRow);
	}
	function deleteRow(row){
		$._post("/authenticated/xx/delete",JSON.stringify({"id":row.id}),function(result){
			if(result.status==200){
				$.messager.alert("提示", "删除成功！");
				grid1.load();
			}else{
				$.messager.alert("提示", "删除失败！<br>"+result.message);
			}
		});
	}


	/**
	 * 初始化搜索条件
	 */
	function initsearch(){
		$('#search-asset_class_id').combotree({
			panelHeight:300,
			icons: [{
				iconCls:'icon-clear',
				handler:function(){
					$('#search-asset_class_id').combotree('clear');
				}
			}],
		    data:grid1.combotreeDatas.class_id
		});
		$('#search-status').combobox({
			panelHeight:'auto',
			editable:false,
			valueField:'code_value',
			textField:'code_name',
			icons: [{
				iconCls:'icon-clear',
				handler:function(e){
					$(e.data.target).combobox('clear');
				}
			}],
		    data:grid1.comboboxDatas.status
		});
	}
</script>
</body>
</html>